# coding=utf-8

import web
import settings
from db import Connection
from applications.account import UserSession

__all__ = ('load_hook', 'unload_hook',)

def load_hook():
	# 创建一个数据库连接对象
	web.ctx.connection = Connection()
	# 单独获取默认库的狗仔，方便调用
	web.ctx.db = web.ctx.connection.default
	# 当前登录用户
	web.ctx.user = UserSession.current()

# TODO: 清除对象
def unload_hook():
	web.ctx.db = None
	del web.ctx.db

	# 释放连接对象
	web.ctx.connection.dispose()
	web.ctx.connection = None
	del web.ctx.connection
